
using UnityEngine;

public class HumanoidUnit : Unit
{
    protected Vector2 m_Velocity;

    protected Vector3 m_LastPosition;

    protected float CurrentSpeed => m_Velocity.magnitude; //当前速度

    void Start()
    {
        m_LastPosition = transform.position; //不然m_LastPosition的初始值就是0,0,0,导致需要移动到你放置的位置，那么启动时就会判定为移动状态
    }
    protected void Update()
    {
        m_Velocity = new Vector2(
            (transform.position.x - m_LastPosition.x),
            (transform.position.y - m_LastPosition.y)
        ) / Time.deltaTime;

        m_LastPosition = transform.position;
        IsMoving = m_Velocity.magnitude > 0;  //移动状态的判定

        m_Animator.SetFloat("Speed", Mathf.Clamp01(CurrentSpeed)); //设置动画速度,并且将速度限制在0-1之间
    }
}